﻿/**  版本信息模板在安装目录下，可自行修改。
* Load_Img.cs
*
* 功 能： N/A
* 类 名： Load_Img
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* V0.01  2017-12-27 10:38:46   N/A    初版
*
* Copyright (c) 2012 Maticsoft Corporation. All rights reserved.
*┌──────────────────────────────────┐
*│　此技术信息为本公司机密信息，未经本公司书面同意禁止向第三方披露．　│
*│　版权所有：动软卓越（北京）科技有限公司　　　　　　　　　　　　　　│
*└──────────────────────────────────┘
*/
using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using DataLib.DBUtility;//Please add references
namespace DataLib.DAL
{
	/// <summary>
	/// 数据访问类:Load_Img
	/// </summary>
	public partial class Load_Img
	{
		public Load_Img()
		{}
		#region  BasicMethod

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("id", "Load_Img"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int id)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from Load_Img");
			strSql.Append(" where id=@id ");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)			};
			parameters[0].Value = id;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(DataLib.Model.Load_Img model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into Load_Img(");
			strSql.Append("loadid,cjoid,loadnum,cjono,Step,StepFlag,createtime,createid,FileName,flag1,flag2,flag3,flag4,flag5,flag6,flag7,flag8)");
			strSql.Append(" values (");
			strSql.Append("@loadid,@cjoid,@loadnum,@cjono,@Step,@StepFlag,@createtime,@createid,@FileName,@flag1,@flag2,@flag3,@flag4,@flag5,@flag6,@flag7,@flag8)");
			SqlParameter[] parameters = {
					new SqlParameter("@loadid", SqlDbType.Int,4),
					new SqlParameter("@cjoid", SqlDbType.Int,4),
					new SqlParameter("@loadnum", SqlDbType.NVarChar,20),
					new SqlParameter("@cjono", SqlDbType.NVarChar,20),
					new SqlParameter("@Step", SqlDbType.Int,4),
					new SqlParameter("@StepFlag", SqlDbType.NVarChar,50),
					new SqlParameter("@createtime", SqlDbType.DateTime),
					new SqlParameter("@createid", SqlDbType.Int,4),
					new SqlParameter("@FileName", SqlDbType.NVarChar,100),
					new SqlParameter("@flag1", SqlDbType.NVarChar,50),
					new SqlParameter("@flag2", SqlDbType.NVarChar,50),
					new SqlParameter("@flag3", SqlDbType.NVarChar,50),
					new SqlParameter("@flag4", SqlDbType.NVarChar,50),
					new SqlParameter("@flag5", SqlDbType.NVarChar,50),
					new SqlParameter("@flag6", SqlDbType.NVarChar,50),
					new SqlParameter("@flag7", SqlDbType.NVarChar,50),
					new SqlParameter("@flag8", SqlDbType.NVarChar,50)};
			parameters[0].Value = model.loadid;
			parameters[1].Value = model.cjoid;
			parameters[2].Value = model.loadnum;
			parameters[3].Value = model.cjono;
			parameters[4].Value = model.Step;
			parameters[5].Value = model.StepFlag;
			parameters[6].Value = model.createtime;
			parameters[7].Value = model.createid;
			parameters[8].Value = model.FileName;
			parameters[9].Value = model.flag1;
			parameters[10].Value = model.flag2;
			parameters[11].Value = model.flag3;
			parameters[12].Value = model.flag4;
			parameters[13].Value = model.flag5;
			parameters[14].Value = model.flag6;
			parameters[15].Value = model.flag7;
			parameters[16].Value = model.flag8;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(DataLib.Model.Load_Img model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update Load_Img set ");
			strSql.Append("loadid=@loadid,");
			strSql.Append("cjoid=@cjoid,");
			strSql.Append("loadnum=@loadnum,");
			strSql.Append("cjono=@cjono,");
			strSql.Append("Step=@Step,");
			strSql.Append("StepFlag=@StepFlag,");
			strSql.Append("createtime=@createtime,");
			strSql.Append("createid=@createid,");
			strSql.Append("FileName=@FileName,");
			strSql.Append("flag1=@flag1,");
			strSql.Append("flag2=@flag2,");
			strSql.Append("flag3=@flag3,");
			strSql.Append("flag4=@flag4,");
			strSql.Append("flag5=@flag5,");
			strSql.Append("flag6=@flag6,");
			strSql.Append("flag7=@flag7,");
			strSql.Append("flag8=@flag8");
			strSql.Append(" where id=@id ");
			SqlParameter[] parameters = {
					new SqlParameter("@loadid", SqlDbType.Int,4),
					new SqlParameter("@cjoid", SqlDbType.Int,4),
					new SqlParameter("@loadnum", SqlDbType.NVarChar,20),
					new SqlParameter("@cjono", SqlDbType.NVarChar,20),
					new SqlParameter("@Step", SqlDbType.Int,4),
					new SqlParameter("@StepFlag", SqlDbType.NVarChar,50),
					new SqlParameter("@createtime", SqlDbType.DateTime),
					new SqlParameter("@createid", SqlDbType.Int,4),
					new SqlParameter("@FileName", SqlDbType.NVarChar,100),
					new SqlParameter("@flag1", SqlDbType.NVarChar,50),
					new SqlParameter("@flag2", SqlDbType.NVarChar,50),
					new SqlParameter("@flag3", SqlDbType.NVarChar,50),
					new SqlParameter("@flag4", SqlDbType.NVarChar,50),
					new SqlParameter("@flag5", SqlDbType.NVarChar,50),
					new SqlParameter("@flag6", SqlDbType.NVarChar,50),
					new SqlParameter("@flag7", SqlDbType.NVarChar,50),
					new SqlParameter("@flag8", SqlDbType.NVarChar,50),
					new SqlParameter("@id", SqlDbType.Int,4)};
			parameters[0].Value = model.loadid;
			parameters[1].Value = model.cjoid;
			parameters[2].Value = model.loadnum;
			parameters[3].Value = model.cjono;
			parameters[4].Value = model.Step;
			parameters[5].Value = model.StepFlag;
			parameters[6].Value = model.createtime;
			parameters[7].Value = model.createid;
			parameters[8].Value = model.FileName;
			parameters[9].Value = model.flag1;
			parameters[10].Value = model.flag2;
			parameters[11].Value = model.flag3;
			parameters[12].Value = model.flag4;
			parameters[13].Value = model.flag5;
			parameters[14].Value = model.flag6;
			parameters[15].Value = model.flag7;
			parameters[16].Value = model.flag8;
			parameters[17].Value = model.id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from Load_Img ");
			strSql.Append(" where id=@id ");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)			};
			parameters[0].Value = id;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string idlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from Load_Img ");
			strSql.Append(" where id in ("+idlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public DataLib.Model.Load_Img GetModel(int id)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 id,loadid,cjoid,loadnum,cjono,Step,StepFlag,createtime,createid,FileName,flag1,flag2,flag3,flag4,flag5,flag6,flag7,flag8 from Load_Img ");
			strSql.Append(" where id=@id ");
			SqlParameter[] parameters = {
					new SqlParameter("@id", SqlDbType.Int,4)			};
			parameters[0].Value = id;

			DataLib.Model.Load_Img model=new DataLib.Model.Load_Img();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public DataLib.Model.Load_Img DataRowToModel(DataRow row)
		{
			DataLib.Model.Load_Img model=new DataLib.Model.Load_Img();
			if (row != null)
			{
				if(row["id"]!=null && row["id"].ToString()!="")
				{
					model.id=int.Parse(row["id"].ToString());
				}
				if(row["loadid"]!=null && row["loadid"].ToString()!="")
				{
					model.loadid=int.Parse(row["loadid"].ToString());
				}
				if(row["cjoid"]!=null && row["cjoid"].ToString()!="")
				{
					model.cjoid=int.Parse(row["cjoid"].ToString());
				}
				if(row["loadnum"]!=null)
				{
					model.loadnum=row["loadnum"].ToString();
				}
				if(row["cjono"]!=null)
				{
					model.cjono=row["cjono"].ToString();
				}
				if(row["Step"]!=null && row["Step"].ToString()!="")
				{
					model.Step=int.Parse(row["Step"].ToString());
				}
				if(row["StepFlag"]!=null)
				{
					model.StepFlag=row["StepFlag"].ToString();
				}
				if(row["createtime"]!=null && row["createtime"].ToString()!="")
				{
					model.createtime=DateTime.Parse(row["createtime"].ToString());
				}
				if(row["createid"]!=null && row["createid"].ToString()!="")
				{
					model.createid=int.Parse(row["createid"].ToString());
				}
				if(row["FileName"]!=null)
				{
					model.FileName=row["FileName"].ToString();
				}
				if(row["flag1"]!=null)
				{
					model.flag1=row["flag1"].ToString();
				}
				if(row["flag2"]!=null)
				{
					model.flag2=row["flag2"].ToString();
				}
				if(row["flag3"]!=null)
				{
					model.flag3=row["flag3"].ToString();
				}
				if(row["flag4"]!=null)
				{
					model.flag4=row["flag4"].ToString();
				}
				if(row["flag5"]!=null)
				{
					model.flag5=row["flag5"].ToString();
				}
				if(row["flag6"]!=null)
				{
					model.flag6=row["flag6"].ToString();
				}
				if(row["flag7"]!=null)
				{
					model.flag7=row["flag7"].ToString();
				}
				if(row["flag8"]!=null)
				{
					model.flag8=row["flag8"].ToString();
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select id,loadid,cjoid,loadnum,cjono,Step,StepFlag,createtime,createid,FileName,flag1,flag2,flag3,flag4,flag5,flag6,flag7,flag8 ");
			strSql.Append(" FROM Load_Img ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" id,loadid,cjoid,loadnum,cjono,Step,StepFlag,createtime,createid,FileName,flag1,flag2,flag3,flag4,flag5,flag6,flag7,flag8 ");
			strSql.Append(" FROM Load_Img ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM Load_Img ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.id desc");
			}
			strSql.Append(")AS Row, T.*  from Load_Img T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "Load_Img";
			parameters[1].Value = "id";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

